﻿/***********************************************************************
 * <copyright file="MapperDto.cs" company="BUCA JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:   Tuanhm
 * Email:    Tuanhm@humg@gmail.com
 * Website:
 * Create Date: Thursday, March 27, 2014
 * Usage: 
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/



using System.Linq;
using System.Collections.Generic;
using AOnlineService.DataTransferObjects.Dictionary;
using BusinessObjects.BussinessDictionary;

namespace AOnlineService.DataTransferObjectMapper 
{
    /// <summary>
    /// Maps DTOs (Data Transfer Objects) to BOs (Business Objects) and vice versa.
    /// </summary>
    public static class Mapper
    {

        #region ToDataTransferObjects
        /// <summary>to
        /// To the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<AccountDto> ToDataTransferObjects(IEnumerable<Account> c)
        {
            return c == null ? null : c.Select(source => ToDataTransferObject((source))).ToList();
        }
       
        /// <summary>to
        /// To the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<EmployTestDto> ToDataTransferObjects(IEnumerable<EmployTest> c)
        {
            return c == null ? null : c.Select(source => ToDataTransferObject((source))).ToList();
        }
        #endregion

        #region ToDataTransferObject.
        /// <summary>
        /// Froms the data transfer object.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static AccountDto ToDataTransferObject(Account c)
        {
            if (c == null) return null;

            return new AccountDto
            {
                AccountId = c.AccountId,
                UnitId = c.UnitId,
                AccountCode = c.AccountCode,
                AccountName = c.AccountName,
                ParentId = c.ParentId,
                Grade = c.Grade,
                IsDetail = c.IsDetail,
                Description = c.Description,
                IsCustomer = c.IsCustomer,
                IsVendor = c.IsVendor,
                IsTax = c.IsTax,
                IsInventoryItem = c.IsInventoryItem,
                IsFixedAsset = c.IsFixedAsset,
                IsActive = c.IsActive,
                IsSystem = c.IsSystem,
            };
        }        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static EmployTestDto ToDataTransferObject(EmployTest c) 
        {
            if (c == null) return null;

            return new EmployTestDto
            {
                EmployId = c.EmployId,
                Name = c.Name,
                Salary = c.Salary,
                DepartmentId = c.DepartmentId               
            };
        }
        #endregion

        #region FromDataTransferObject        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static EmployTest FromDataTransferObject(EmployTestDto c)
        {
            if (c == null) return null;

            return new EmployTest
            {
                EmployId = c.EmployId,
                Name = c.Name,
                Salary = c.Salary,
                DepartmentId = c.DepartmentId   
            };
        }

        /// <summary>
        /// Froms the data transfer object.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static Account FromDataTransferObject(AccountDto c)
        {
            if (c == null) return null;

            return new Account
            {
                AccountId = c.AccountId,
                UnitId = c.UnitId,
                AccountCode = c.AccountCode,
                AccountName = c.AccountName,
                ParentId = c.ParentId,
                Grade = c.Grade,
                IsDetail = c.IsDetail,
                Description = c.Description,              
                IsCustomer = c.IsCustomer,
                IsVendor = c.IsVendor,
                IsTax = c.IsTax,
                IsInventoryItem = c.IsInventoryItem,
                IsFixedAsset = c.IsFixedAsset,
                IsActive = c.IsActive,
                IsSystem = c.IsSystem,
            };
        }
        #endregion

        #region FromDataTransferObjects
        /// <summary>
        /// Froms the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<Account> FromDataTransferObjects(IEnumerable<AccountDto> c)
        {
            return c == null ? null : c.Select(source => FromDataTransferObject((source))).ToList();
        }
        
        /// <summary>
        /// Froms the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<EmployTest> FromDataTransferObjects(IEnumerable<EmployTestDto> c)
        {
            return c == null ? null : c.Select(source => FromDataTransferObject((source))).ToList();
        }
        #endregion

    }
}